
//会传一个map进来
// const map = {
//     Space: {
//         keydown: startAttack,
//         keyup: stopAttack
//     }
// }

const { onMounted, onUnmounted } = require("vue");

export default function(map) {
    const keydownHandler = function(e) {
        const code = e.code
        if(map[code]){
            map[code].keydown()
        }  
    }
    
    const keyupHandler = function(e) {
        const code = e.code
        if(map[code]){
            map[code].keyup()
        } 
    }
    
    onMounted(()=>{
        window.addEventListener('keydown', keydownHandler)
        window.addEventListener('keyup', keyupHandler)
    })
    onUnmounted(()=>{
        window.removeEventListener('keydown', keydownHandler)
        window.removeEventListener('keyup', keyupHandler)
    })
} 

